package com.itdr.db;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

/**
 * mybatis-plus代码生成器执行类
 * 日期: 2020/10/20 15:59
 *
 * @author Air张
 * @since JDK 1.8
 */
public class CodeGenerator {
    public static void main(String[] args) {
        // 创建代码生成器核心对象
        AutoGenerator mpg = new AutoGenerator();
        // 创建全局配置对象
        GlobalConfig gc = new GlobalConfig();
        // 获取当前工程路径
        String projectPath = System.getProperty("user.dir");
        // 设置生成文件的输出目录
        gc.setOutputDir(projectPath + "/src/main/java");
        // 覆盖已有文件
        gc.setFileOverride(true);
        // 设置开发人员名称
        gc.setAuthor("AirZhang");


        // 数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setUrl("jdbc:mysql://localhost:3306/test?useUnicode=true&useSSL=false&characterEncoding=utf8");
        dsc.setDriverName("com.mysql.jdbc.Driver");
        dsc.setUsername("root");
        dsc.setPassword("123456");


        // 包配置
        PackageConfig pc = new PackageConfig();
        pc.setParent("com.itdr");


        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        strategy.setNaming(NamingStrategy.underline_to_camel);
        strategy.setEntityLombokModel(true);
        strategy.setRestControllerStyle(true);
        strategy.setTablePrefix("neuedu_");
        strategy.setInclude(
                new String[]{
                        "neuedu_cart",
                        "neuedu_user",
                        "neuedu_category",
                        "neuedu_order",
                        "neuedu_order_item",
                        "neuedu_shipping",
                        "neuedu_payinfo",
                        "neuedu_product",
                }
        );

        // 加载全局配置
        mpg.setGlobalConfig(gc);
        // 加载数据源
        mpg.setDataSource(dsc);
        // 加载包配置
        mpg.setPackageInfo(pc);
        // 加载策略配置
        mpg.setStrategy(strategy);
        // 执行
        mpg.execute();
    }
}